

package dynamicdiscountsystem;

import com.mysql.jdbc.PreparedStatement;
import java.io.IOException;
import java.sql.SQLException;
import java.text.DateFormat;
import javax.swing.JOptionPane;

public class Discount3Frame extends javax.swing.JInternalFrame {

    /** Creates new form Discount3Frame */
    public Discount3Frame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldLimitProductNumber = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jCalendarComboFrom = new org.freixas.jcalendar.JCalendarCombo();
        jLabel3 = new javax.swing.JLabel();
        jCalendarComboTo = new org.freixas.jcalendar.JCalendarCombo();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldPayingProductNumber = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setTitle("N al M ödə kompaniyası");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Endirim Məlumatları"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel1.setText("- tarixinədək , eyni maldan");

        jTextFieldLimitProductNumber.setFont(new java.awt.Font("Tahoma", 0, 12));
        jTextFieldLimitProductNumber.setText("5");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel2.setText("- tarixindən");

        jCalendarComboFrom.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "June 14, 2011" }));
        jCalendarComboFrom.setDateFormat(DateFormat.getDateInstance(DateFormat.LONG,
            getLocale()));

    jLabel3.setFont(new java.awt.Font("Tahoma", 0, 13));
    jLabel3.setText("dənə");

    jCalendarComboTo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "June 14, 2011" }));
    jCalendarComboTo.setDateFormat(DateFormat.getDateInstance(DateFormat.LONG,
        getLocale()));

jLabel4.setFont(new java.awt.Font("Tahoma", 0, 13));
jLabel4.setText("alan hər bir şəxs");

jTextFieldPayingProductNumber.setFont(new java.awt.Font("Tahoma", 0, 12));
jTextFieldPayingProductNumber.setText("3");

jLabel5.setFont(new java.awt.Font("Tahoma", 0, 13));
jLabel5.setText("- nin qiymətini ödəyəcək.");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jCalendarComboFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jCalendarComboTo, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldLimitProductNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextFieldPayingProductNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jCalendarComboFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2)
                .addComponent(jCalendarComboTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel1)
                .addComponent(jTextFieldLimitProductNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(jTextFieldPayingProductNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel5))
            .addContainerGap(44, Short.MAX_VALUE))
    );

    jButton1.setFont(new java.awt.Font("Tahoma", 0, 12));
    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dynamicdiscountsystem/resources/ok.gif"))); // NOI18N
    jButton1.setText("Əlavə et");
    jButton1.setHideActionText(true);
    jButton1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
    jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
    jButton1.setInheritsPopupMenu(true);
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(jButton1)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(38, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jButton1)
            .addContainerGap())
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents


     private void ActionPerfomed() throws SQLException, IOException {
        java.sql.Date dateFrom = new java.sql.Date(jCalendarComboFrom.getDate().getTime());
        java.sql.Date dateTo = new java.sql.Date(jCalendarComboTo.getDate().getTime());

        int limitProductNumber = Integer.valueOf(jTextFieldLimitProductNumber.getText());
        int payingProductNumber = Integer.valueOf(jTextFieldPayingProductNumber.getText());

        DatabaseConnection db = new DatabaseConnection();
        PreparedStatement ps = null;
        try {
            db.ConnectionOpen();
            ps = (PreparedStatement) db.conn.prepareStatement("INSERT INTO DISCOUNT3 (DATE_FROM , DATE_TO,"
                    + "LIMIT_PRODUCT_NUMBER , PAYING_PRODUCT_NUMBER) VALUES(?,?,?,?)");
            ps.setDate(1, dateFrom);
            ps.setDate(2, dateTo);
            ps.setInt(3, limitProductNumber);
            ps.setInt(4, payingProductNumber);
            ps.execute();
            JOptionPane.showMessageDialog(null,
                    "Məlumat əlavə edildi.",
                    "İnformasiya", JOptionPane.INFORMATION_MESSAGE);
        } finally {
            if (ps != null) {
                ps.close();
            }
            db.ConnectionClose();
        }
    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            ActionPerfomed();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,
                    "Xəta baş verdi.\nXəta mesajı = " + ex.getMessage(),
                    "Xəta", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private org.freixas.jcalendar.JCalendarCombo jCalendarComboFrom;
    private org.freixas.jcalendar.JCalendarCombo jCalendarComboTo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextFieldLimitProductNumber;
    private javax.swing.JTextField jTextFieldPayingProductNumber;
    // End of variables declaration//GEN-END:variables

}
